package net.huanger.gametools.mapeditor.ui;

import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import net.huanger.gametools.mapeditor.model.MapModel;
import net.huanger.gametools.mapeditor.ui.impl.AroundOperate;
import net.huanger.gametools.mapeditor.ui.impl.BlockOperate;
import net.huanger.gametools.mapeditor.ui.impl.EventOperate;
import net.huanger.gametools.mapeditor.ui.impl.GuidesOperate;
import net.huanger.gametools.mapeditor.ui.impl.PuzzleOperate;

public class OperateContext
{
  public  Operate puzzleOperate;
  public  Operate blockOperate;
  public  Operate eventOperate;
  private  Operate  currentOperate;
  private Operate guidesOperate;
  private  List<Operate> context;
  private int row;
  private int column;
  public OperateContext(int row,int column){
    this.row=row;
    this.column=column;
    context=new ArrayList<Operate>();
    context.add(puzzleOperate=new PuzzleOperate(row,column));
    context.add(blockOperate=new BlockOperate(row,column));
    context.add(eventOperate=new EventOperate(row,column));
    context.add(guidesOperate=new GuidesOperate(row, column));
    context.add(new AroundOperate(row, column));
  }
  public  void setCurrentOperate(Operate type){
    currentOperate=type;
  }
  public IDiv getTiteDiv(){
    return puzzleOperate.getMapDiv();
  }
  public IDiv getBlockDiv(){
    return blockOperate.getMapDiv();
  }
  public IDiv getEventDiv(){
    return eventOperate.getMapDiv();
  }
  public  Collection<Operate> getAllOperates(){
    return context;
  }
  public void selectPuzzle()
  {
    currentOperate=puzzleOperate;
  }
  public void selectEvent()
  {
    currentOperate=eventOperate;
  }
  public void selectBlock()
  {
    currentOperate=blockOperate;
  }
  public void mapClick(MouseEvent e)
  {
    if(currentOperate==null)return ;
    currentOperate.mapClick(e);
  }
  public void titeClick(MouseEvent e, int row, int column)
  {
    if(currentOperate==null)return ;
    currentOperate.titeClick(e, row, column);
  }
  public IDiv getGuidesDiv()
  {
    return guidesOperate.getMapDiv();
  }
  public int getRow()
  {
    return row;
  }
  public int getColumn()
  {
    return column;
  }
  public void initMapData(MapModel mm)
  {
    if(mm==null)return;
    for(Operate o:getAllOperates()){
      IDiv mapDiv = o.getMapDiv();
      if(mapDiv.hasData()){
        mapDiv.restoreData(mm);
      }
    }
  }
}
